#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 810;
const int inf = 0x3f3f3f3f;

int dis[N],cost;
int maxflow,n,m,a,b,S,T,incf[N],h[N],cnt = 1,pre[N];
bool vis[N];
struct edge{int v,w,c,nxt;}e[N<<2];
void link(int x,int y,int w,int c){e[++cnt] = (edge){y,w,c,h[x]};h[x] = cnt;e[++cnt] = (edge){x,0,-c,h[y]};h[y] = cnt;}

int id(int x,int y){return (x - 1) * m + y;}

bool spfa(){
	memset(dis,0x3f,sizeof(dis)); memset(vis,0,sizeof(vis)); dis[S] = 0; queue<int> q;q.push(S);vis[S] = 1; incf[S] = 0x3f3f3f3f;
	while(q.size()){
		int x = q.front();q.pop();
		for(int i = h[x],y;i;i = e[i].nxt){
			if(dis[y = e[i].v] > dis[x] + e[i].c && e[i].w){
				dis[y] = dis[x] + e[i].c; pre[y] = i; incf[y] = min(incf[x],e[i].w);
				if(!vis[y]) q.push(y),vis[y] = 1;
			}
		}vis[x] = 0;
	}return dis[T] < 0x3f3f3f3f;
}

void update(){
	int x = T;
	while(x ^ S){int i = pre[x]; e[i].w -= incf[T];e[i^1].w += incf[T]; x = e[i^1].v;}
	maxflow += incf[T]; cost += dis[T] * incf[T];
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	a = in,b = in,n = in+1,m = in+1;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j < m;j++){
			int x = id(i,j),y = id(i,j+1),val = in;
			link(x,y,1,-val); link(x,y,inf,0);
		}
	for(int j = 1;j <= m;j++)
		for(int i = 1;i < n;i++){
			int x = id(i,j),y = id(i+1,j),val = in;
			link(x,y,1,-val); link(x,y,inf,0);
		}
	S = 0; T = n * m + 2;
	for(int i = 1;i <= a;i++){int k = in,x = in+1,y = in+1; link(S,id(x,y),k,0);}
	for(int i = 1;i <= b;i++){int k = in,x = in+1,y = in+1; link(id(x,y),T,k,0);}
	while(spfa()) update();
	printf("%d\n",-cost);
	return 0;
}
